package com.huangsm.book.designmodel;

import com.fasterxml.jackson.core.io.OutputDecorator;

import java.io.OutputStream;
import java.util.zip.InflaterOutputStream;

/**
 * 具体装饰器，完成数据包HTTP头部的处理，
 * 其余业务处理交给内部的component完成
 *
 * @author huang
 * @PACKAGE_NAME com.huangsm.book.designmodel
 * @PROJECT_NAME concurrence
 * @date 2019/2/15
 */
public class PacketHTTPHeaderCreator extends PacketDecorator {
    public PacketHTTPHeaderCreator(IPacketCreator c) {
        super(c);
    }

    @Override
    public String handleContent() {
        StringBuffer sb = new StringBuffer();
        sb.append("Cache-Control:no-cache\n");
        sb.append("Date:Mon.31Dec201902:23:56CMT\n");
        sb.append(component.handleContent());
        return sb.toString();
    }

    /**
     * 装饰者模式的使用方法
     */
    public static void main(String[] args) {
        IPacketCreator ip = new PacketHTTPHeaderCreator(
                new PacketHTMLHeaderCreator(
                        new PacketBodyCreator()));
        System.out.println(ip.handleContent());
    }
}
